<template>
  <div class="app-container">
    <el-form  :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="班级" prop="className">
        <el-select v-model="queryParams.className" @change="changeStudentList($event)" placeholder="请选择班级" :style="{width: '100%'}" >
          <el-option v-for="(item, index) in classesList" :key="index" :label="item.className"
                     :value="item.className" ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="阶段" prop="stage">
        <el-select v-model="queryParams.stage" placeholder="请选择阶段" clearable>
          <el-option
            v-for="dict in dict.type.sys_stage"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="日期" prop="date">
        <el-date-picker clearable
                        v-model="queryParams.date"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="第几天" prop="day">
        <el-input
          v-model="queryParams.day"
          placeholder="请输入第几天"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAddPlan"
          v-hasPermi="['teaching:plan:add']"
        >设计教学计划</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="planList" @selection-change="handleSelectionChange" :row-class-name="tableRowClassName">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="日期" align="center" prop="date" fixed="left">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.date, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="班级名字" align="center" prop="className" />
      <el-table-column label="阶段" align="center" prop="stage" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_stage" :value="scope.row.stage"/>
        </template>
      </el-table-column>
      <el-table-column label="周几" align="center" prop="weekday">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.ya_weekday" :value="scope.row.weekday"/>
        </template>
      </el-table-column>
      <el-table-column label="第几天" align="center" prop="day" />
      <el-table-column label="授课内容" align="center" prop="courseContent" />
      <el-table-column label="备注" align="center" prop="remarks" />
      <el-table-column label="班主任记录" align="center" prop="patrolAndCommunicationRecord" />
      <el-table-column label="整体学习情况" align="center" prop="studentLearningStatus" />
      <el-table-column label="出席/缺席/迟到/请假" align="center" prop="stage" >
        <template slot-scope="scope">
          {{scope.row.presentCount}}/{{scope.row.absentCount}}/{{scope.row.lateCount}}/{{scope.row.excusedCount}}
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        width="200">
        <template slot-scope="scope" >
          <el-button v-show="scope.row.courseContent!='周日休息' && scope.row.courseContent!='自习'"
                     size="mini"
                     type="text"
                     icon="el-icon-search"
                     @click="checkDailyTask(scope.row)"
                     v-hasPermi="['teaching:tasks:edit']"
          >每日任务</el-button>
          <el-button v-show="scope.row.courseContent!='周日休息'" @click="handleAddTracking(scope.row)" type="text" size="small">教学跟踪</el-button>
          <el-button v-show="scope.row.courseContent!='周日休息'" @click="handleAddAttendance(scope.row)" type="text" size="small">考勤</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :page-sizes="[200,500]"
      :page-size="200"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 任务完成情况对话框 -->
    <el-dialog title="每日任务完成情况" :visible.sync="completionOpen" fullscreen  append-to-body>
      <el-form :inline="true" ref="completionForm" class="demo-form-inline" :model="completionForm" :rules="completionRules" label-width="80px">
        <el-form-item label="完成状态" prop="status" >
          <el-select v-model="completionForm.status" placeholder="请选择完成状态" clearable>
            <el-option
              v-for="dict in dict.type.ya_task_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学生名字" prop="status" >
          <el-input v-model="completionForm.studentName"  >
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="checkDailyTask">查询</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="completionLoading" style="width: 100%" :data="completionList" >
        <el-table-column label="学生名字" align="center" prop="studentName">
        </el-table-column>
        <el-table-column label="学生账号" align="center" prop="username">
        </el-table-column>
        <el-table-column label="任务状态" align="center" prop="status">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.ya_task_status" :value="scope.row.status"/>
          </template>
        </el-table-column>
        <el-table-column label="日期" align="center" prop="date">
        </el-table-column>
        <el-table-column label="总结图片" align="center" prop="summaryPicUrl" >
          <template slot-scope="scope">
            <el-image v-if="scope.row.summaryPicUrl"
                      style="width: 50px; height: 50px"
                      :src="`${baseUrl}${scope.row.summaryPicUrl}`"
                      :preview-src-list="preList(baseUrl+scope.row.summaryPicUrl)">
            </el-image>
            <span v-else>未上传</span>
          </template>
        </el-table-column>
        <el-table-column label="难点反馈" align="center" prop="difficultyFeedback" />
        <el-table-column label="是否合格" align="center" prop="qualified" >
          <template slot-scope="scope">
            <el-select  v-model="scope.row.qualified" clearable @change="updateQualified(scope.row)">
              <el-option
                v-for="dict in dict.type.ya_task_qualified"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="100">
          <template slot-scope="scope" >
            <el-button v-show="scope.row.courseContent!='周日休息'"
                       size="mini"
                       type="text"
                       icon="el-icon-search"
                       @click="checkInterview(scope.row)"
                       v-hasPermi="['teaching:tasks:edit']"
            >查看面试题</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelCompletion">关闭</el-button>
      </div>
    </el-dialog>
    <el-drawer
      title="面试题练习情况"
      :visible.sync="drawer"
      :direction="direction"
      :before-close="handleClose" :size="'80%'">
      <el-card class="box-card" v-for="(interview,index) in interviewList">
        <el-form ref="form" :model="interviewForm" :rules="rules" label-width="80px">
          <el-form-item :label="'题目'+(index+1)" >
            {{interview.question}}
          </el-form-item>
          <el-form-item label="答案" prop="answer">
            <el-input v-model="interview.answer" :id="'answer'+interview.interviewId" autosize :ref="'answer'+interview.interviewId" type="textarea" onpaste="return false;" placeholder="答案" />
          </el-form-item>
          <el-form-item label="参考答案" prop="answer" v-if="interview.referenceAnswer">
            <mavon-editor v-model="interview.referenceAnswer" :subfield="false" defaultOpen="preview" :editable="false" :toolbarsFlag="false" />
          </el-form-item>
          <el-form-item label="难点" prop="difficulty" v-if="interview.difficulty">
            <el-input v-model="interview.difficulty" type="textarea" autosize onpaste="return false;" placeholder="对于参考答案哪里不理解" />
          </el-form-item>
          <el-form-item label="what" prop="what"  v-if="interview.what">
            <el-input v-model="interview.what" type="textarea" autosize onpaste="return false;" placeholder="是什么" />
          </el-form-item>
          <el-form-item label="how" prop="how" v-if="interview.how">
            <el-input v-model="interview.how" type="textarea" autosize onpaste="return false;" placeholder="怎么用" />
          </el-form-item>
          <el-form-item label="why" prop="why" v-if="interview.why">
            <el-input v-model="interview.why" type="textarea" autosize  onpaste="return false;" placeholder="有什么用" />
          </el-form-item>
          <el-form-item label="if when" prop="ifThen" v-if="interview.ifThen">
            <el-input v-model="interview.ifThen" type="textarea" autosize onpaste="return false;" placeholder="什么场景下用" />
          </el-form-item>
        </el-form>
      </el-card>
    </el-drawer>

    <el-dialog title="智能生成教学计划" v-bind="$attrs" :visible.sync="open" width="90%" v-on="$listeners"  fullscreen>
      <el-form :inline="true" class="demo-form-inline" ref="form" :model="form" :rules="rules" size="medium" label-width="120px">
        <el-form-item label="班级" prop="className">
          <el-select v-model="form.className" @change="changeStudentList($event)" placeholder="请选择班级" :style="{width: '100%'}" >
            <el-option v-for="(item, index) in classesList" :key="index" :label="item.className"
                       :value="item.className" ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="阶段" prop="stage">
          <el-select v-model="form.stage" placeholder="请选择阶段" clearable>
            <el-option
              v-for="dict in dict.type.sys_stage"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="阶段开始时间" >
          <el-date-picker
            v-model="form.beginDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="medium" @click="queryTeachingPlan"> 查询已有计划 </el-button>
          <el-button type="warning" icon="el-icon-scissors"  size="medium" @click="previewTeachingPlan" > 重新创建预览 </el-button>
          <el-button type="danger" icon="el-icon-date"  size="medium" @click="clearConfig" > 重置调休配置 </el-button>
          <el-button
            type="danger"
            icon="el-icon-delete"
            @click="handleDelete"
            v-hasPermi="['teaching:plan:remove']"
          >删除</el-button>
        </el-form-item>
        <el-table
          :data="planAllList"
          style="width: 100%"
          :row-class-name="tableRowClassName">
          <el-table-column
            prop="date"
            label="日期"
            width="180">
          </el-table-column>
          <el-table-column
            prop="className"
            label="班级">
          </el-table-column>
          <el-table-column
            prop="stage"
            label="阶段">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.sys_stage" :value="scope.row.stage"/>
            </template>
          </el-table-column>
          <el-table-column
            prop="weekday"
            label="周几"
            width="90">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.ya_weekday" :value="scope.row.weekday"/>
            </template>
          </el-table-column>
          <el-table-column
            prop="day"
            label="第几天">
          </el-table-column>
          <el-table-column
            prop="courseContent"
            label="课程内容"
            width="180">
            <template slot-scope="scope">
              <el-input v-model="scope.row.courseContent" ></el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop="remarks"
            label="备注"
            width="180">
            <template slot-scope="scope">
              <el-input v-model="scope.row.remarks" ></el-input>
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="success"
                @click="addHoliday(scope.$index, scope.row,'休息')" v-if="!isHoliday(scope.row)">休息</el-button>
              <el-button
                size="mini"
                type="warning"
                @click="addHoliday(scope.$index, scope.row,'自习')" v-if="!isHoliday(scope.row)">自习</el-button>
              <el-button
                size="mini"
                type="danger"
                @click="addWorkday(scope.$index, scope.row)" v-if="isHoliday(scope.row) && !scope.row.courseContent.includes('节')">上课</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="handleConfirm" >提交修改</el-button>
      </div>
    </el-dialog>
    <el-dialog title="添加教学跟踪信息" fullscreen :visible.sync="tracking_open" width="500px" append-to-body>
      <el-form ref="trackingForm" :model="trackingForm" :rules="rules" label-width="180px">
        <el-form-item label="未完成作业及未反馈名单" prop="unfinishedHomeworkAndUnfeedbackList">
          <el-input v-model="trackingForm.unfinishedHomeworkAndUnfeedbackList" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="巡课记录/班主任沟通" prop="patrolAndCommunicationRecord">
          <el-input v-model="trackingForm.patrolAndCommunicationRecord" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="学员学习情况" prop="studentLearningStatus">
          <el-input v-model="trackingForm.studentLearningStatus" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="关注学员处理方案" prop="studentAttentionProcessingPlan">
          <el-input v-model="trackingForm.studentAttentionProcessingPlan" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitTrackingForm">确 定</el-button>
        <el-button @click="cancelTrackingForm">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog title="考勤" fullscreen :visible.sync="attendance_open" width="500px" append-to-body>
      <el-form ref="attendanceForm" :model="attendanceForm" :rules="rules" label-width="180px">
          <el-form-item label="时间段">
              <el-col span="8">
                  <el-radio-group v-model="timeSlot" width="200px"  @change="queryAttendanceList(studentAttendanceList[0].classesId,studentAttendanceList[0].date,studentAttendanceList[0].stage)">
                      <el-radio :label="dict.value" v-for="dict in dict.type.ya_attendance_day">{{dict.label}}</el-radio>
                  </el-radio-group>
              </el-col>
          </el-form-item>
        <el-form-item :label="stu.name" v-for="stu in studentAttendanceList">
          <el-col span="8">
            <el-radio-group v-model="stu.attendance" width="200px">
              <el-radio :label="dict.value" v-for="dict in dict.type.ya_attendance_status">{{dict.label}}</el-radio>
            </el-radio-group>
          </el-col>
          <el-col span="8">
            <el-input
              type="textarea"
              :rows="1"
              placeholder="备注信息"
              v-model="stu.remark">
            </el-input>
          </el-col>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitAttendanceForm">确 定</el-button>
        <el-button @click="cancelAttendanceForm">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<style>
.el-table .warning-row {
  background: #34bfa3;
}

.el-table .success-row {
  background: #f0f9eb;
}

.el-table .yellow-row {
  background: #e6a700;
}
</style>
<script>
import { clearConfig,addWorkday,addHoliday,previewTeachingPlan,listAllPlan,listPlan, getPlan, delPlan, addPlan, updatePlan } from "@/api/teaching/teaching_plan";
import {listAllClasses} from "@/api/teaching/classes";
import {listAttendance,updateAttendance} from "@/api/teaching/attendance";
// import { listTeaching_tracking, getTeaching_tracking, delTeaching_tracking, addTeaching_tracking, updateTeaching_tracking } from "@/api/teaching/teaching_tracking";
// import {listAllStudent } from "@/api/teaching/student";
// import {getCompletion, queryDailyInterviewList,queryDailyInterviewListById, updateQualified} from "@/api/teaching/daily_tasks";
export default {
  name: "Plan",
  dicts: ['sys_stage','ya_attendance_status','ya_weekday','ya_task_status','ya_task_qualified','ya_attendance_day'],
  data() {
    return {
      drawer: false,
      direction: 'ltr',
      interviewList:[],
      baseUrl: process.env.VUE_APP_BASE_API,
      planId:null,
      completionList:[],
      completionOpen:false,
      completionLoading:false,
      completionForm: {},
      //考勤时间段
      timeSlot:undefined,
      //学员考勤信息
      studentAttendanceList:[],
      classesList: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 教学计划表格数据
      planList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      tracking_open:false,
      attendance_open:false,
      trackingForm:{},
      attendanceForm:{},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 180,
        date: null,
        day: null,
        courseContent: null,
        className: null,
        stage: null
      },
      // 表单参数
      form: {
        className: undefined,
        stage: undefined,
        beginDate:""
      },
      interviewForm: {
      },
      // 表单校验
      rules: {
        date: [
          { required: true, message: "日期不能为空", trigger: "blur" }
        ],
        day: [
          { required: true, message: "第几天不能为空", trigger: "blur" }
        ],
        courseContent: [
          { required: true, message: "授课内容不能为空", trigger: "blur" }
        ],
        remarks: [
          { required: true, message: "备注事项不能为空", trigger: "blur" }
        ],
        className: [
          { required: true, message: "班级名字不能为空", trigger: "blur" }
        ],
        class_id: [{
          required: true,
          message: '请选择班级',
          trigger: 'change'
        }],
        stage: [{
          required: true,
          message: '请选择阶段',
          trigger: 'change'
        }],
        beginDate: [{
          required: true,
          message: '请选择起始日期',
          trigger: 'change'
        }]
      },
      generationDisabled:true,
      planAllList:[]
    };
  },
  created() {
    this.getList();
    this.getClassesList();
  },
  methods: {
    handleClose(done) {
      done();
    },
    checkInterview(row){
      queryDailyInterviewListById(row.id).then(response=>{
        this.interviewList = response.rows;
        this.drawer = true;
      });
    },
    preList(url){
      return url.split(",");
    },
    cancelCompletion(){
      this.completionOpen = false;
      this.resetDailyTask();
    },
    updateQualified(row){
      let dailyTaskId = row.id;
      let qualified = row.qualified;
      updateQualified({dailyTaskId,qualified}).then(response => {
        this.$modal.msgSuccess("更新成功");
      }).catch(err=>{
        this.$modal.msgError("更新失败");
      });
    },
    resetDailyTask() {
      this.completionForm = {
        date: null,
        status:null,
        studentName:null,
        classesId:null,
      };
      this.resetForm("completionForm");
    },
    checkDailyTask(row) {
      if(row.date){
        this.resetDailyTask();
        this.completionForm.date = row.date
        this.completionForm.classesId = row.classesId
      }
      this.completionLoading = true;
      getCompletion(this.completionForm).then(response => {
        this.completionList = response.rows;
        this.completionOpen = true;
        this.completionLoading = false;
      });
    },
    submitAttendanceForm() {
    // ,this.classesId,this.timeSlot
      updateAttendance(this.studentAttendanceList).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.attendance_open = false;
        this.getList();
      });
    },
    submitTrackingForm() {
      this.$refs["trackingForm"].validate(valid => {
        if (valid) {
          updateTeaching_tracking(this.trackingForm).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.tracking_open = false;
            this.getList();
          });
        }
      });
    },
    handleAddTracking(row) {
      this.resetTrackingForm();
      this.title = "编辑教学跟踪信息";
      this.tracking_open = true;

      getTeaching_tracking(row.date,row.classesId).then(response => {
        if (response.data) {
          this.trackingForm = response.data;
        }else {
          this.trackingForm.teachingPlanId=row.id;
          this.trackingForm.date=row.date;
          this.trackingForm.classesId=row.classesId;
        }
      })
    },
    queryAttendanceList(classesId,date,stage){
      //查询出这个班所有学生
      listAttendance({"classesId":classesId,"date":date,"stage":stage,"timeSlot":this.timeSlot}).then(response => {
        this.studentAttendanceList = response.rows;
        this.timeSlot = this.studentAttendanceList[0].timeSlot + ""
      });
    },
    handleAddAttendance(row) {
      this.resetTrackingForm();
      this.classesId = row.classesId;
      this.stage = row.stage;
      this.attendance_open = true;
      //查询出这个班所有学生
      listAttendance({"classesId":row.classesId,"date":row.date,"stage":row.stage}).then(response => {
        //radio默认值是string，需要将int转string
        response.rows.forEach(stu=>{
          stu.attendance = stu.attendance + "";
          //设置默认考勤日期
          stu.date=row.date;
        })
        this.studentAttendanceList = response.rows;
        this.timeSlot = this.studentAttendanceList[0].timeSlot + ""
      });
    },
    // 表单重置
    resetTrackingForm() {
      this.trackingForm = {
        id : null,
        teachingPlanId: null,
        unfinishedHomeworkAndUnfeedbackList: null,
        leaveNumber: null,
        lateNumber: null,
        patrolAndCommunicationRecord: null,
        studentLearningStatus: null,
        studentAttentionProcessingPlan: null
      };
      this.resetForm("trackingForm");
    },
    // 表单重置
    resetAttendanceForm() {
      this.attendanceStatusList = [];
      this.resetForm("attendanceForm");
    },
    getClassesList() {
      listAllClasses().then(response => {
        this.classesList = response.rows;
      });
    },
    isHoliday(row){
      if (row.courseContent === '自习' || row.courseContent.includes('节') || row.courseContent.includes('休息')) {
        return true;
      }
      else {
        return false;
      }
    },
    tableRowClassName({row, rowIndex}) {
      if (row.courseContent === '自习' ) {
        return 'yellow-row';
      }else if(row.courseContent.includes('节') || row.courseContent.includes('休息')){
        return 'warning-row';
      }
      else {
        return 'success-row';
      }
      return '';
    },
    /** 查询教学计划列表 */
    getList() {
      this.loading = true;
      listPlan(this.queryParams).then(response => {
        this.planList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮
    cancelTrackingForm() {
      this.tracking_open = false;
      this.resetTrackingForm();
    },
    cancelAttendanceForm() {
      this.attendance_open = false;
      this.resetAttendanceForm();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        date: null,
        day: null,
        courseContent: null,
        remarks: null,
        className: null,
        stage: null,
        beginDate: ""
      };
      this.resetForm("form");
      this.planAllList = [];
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAddPlan() {
      this.reset();
      this.open = true;
      this.title = "添加教学计划";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPlan(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改教学计划";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePlan(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPlan(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          let v = this;
          this.$modal.confirm('删除后相关的数据不会有影响，可以删除后重新创建！是否确认该阶段删除教学计划？').then(function() {
            delPlan(v.form);
            v.planAllList = [];
          })
        }
      })

    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('teaching/plan/export/plan', {
        ...this.queryParams
      }, `plan_${new Date().getTime()}.xlsx`)
    },
    onOpen() {},
    onClose() {
      this.$refs['form'].resetFields()
    },
    close() {
      this.$emit('update:visible', false)
    },
    handleConfirm() {
      let data = {
        teachingPlanList : this.planAllList,
      };
      Object.assign(data,  this.form);
      console.log(data)
      addPlan(data).then(response => {
        this.$modal.msgSuccess("新增成功");
        this.open = false;
        this.getList();
      });
    },
    queryTeachingPlan(){
      this.$refs["form"].validate(valid => {
        if (valid) {
          listAllPlan(this.form).then(response => {
            this.planAllList = response.rows;
            if(response.rows.length==0){
              this.generationDisabled=false;
              this.$modal.msgSuccess("该班级还未创建教学计划！");
            }else{
              this.generationDisabled=true;
              //获取第一天计划日期
              this.form.beginDate = response.rows[0].date;
              this.$modal.msgWarning("该班级已经创建教学计划，请细心修改！");
            }
          });
        }})
    },
    clearConfig(){
      this.$refs["form"].validate(valid => {
        if (valid) {
          clearConfig(this.form).then(response => {
            this.planAllList = response.rows;
          });
        }})
    },
    previewTeachingPlan() {
      // if (!this.form.beginDate || this.form.beginDate == "") {
      //   this.$modal.msgWarning("请选择开课日期！");
      //   return;
      // }
      previewTeachingPlan(this.form).then(response => {
        this.planAllList = response.data;
        if(response.data.length==0){
          this.generationDisabled=false;
          this.$modal.msgSuccess("该班级还未创建教学计划！");
        }
      }).catch(error => {
        this.$modal.msgError(error.response.data.msg);
      });
    },
    addHoliday(i,row,type) {
      row.beginDate = this.form.beginDate;
      row.type = type;
      console.log(row.type);
      addHoliday(row).then(response => {
        this.planAllList = response.data;
        if(response.data.length==0){
          this.generationDisabled=false;
          this.$modal.msgSuccess("该班级还未创建教学计划！");
        }
      });
    },
    addWorkday(i,row) {
      row.beginDate = this.form.beginDate;
      console.log(row)
      addWorkday(row).then(response => {
        this.planAllList = response.data;
        if(response.data.length==0){
          this.generationDisabled=false;
          this.$modal.msgSuccess("该班级还未创建教学计划！");
        }
      });
    },
  }
};
</script>
